#include "file.h"

#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>

const char File::Separator = '/';

using namespace std;

File::File()
{
}

File::~File()
{
}

bool File::exists(const string& filePath)
{
  struct stat statbuf;

  if(stat(filePath.c_str(), &statbuf) >= 0 && S_ISREG(statbuf.st_mode))
  {
    return true;
  }

  return false;
}

int File::fileType(const string& filePath)
{
  int ret;
  struct stat statbuf;

  if(filePath.length() > 0 && filePath[0] == '.')
    ret = ShowDotFiles;
  else
    ret = None;

  if(stat(filePath.c_str(), &statbuf))
  {
    if(S_ISDIR(statbuf.st_mode))
    {
      ret |= Directories;
    } else if(S_ISREG(statbuf.st_mode))
    {
      ret |= Files;
    }
  }

  return ret;
}
